<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="税率" prop="tax">
                <el-input v-model="queryParams.tax" placeholder="请输入税率"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="发票金额" prop="money">
                <el-input v-model="queryParams.money" placeholder="请输入发票金额"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="剩余发票" prop="shengyu">
                <el-input v-model="queryParams.shengyu" placeholder="请输入剩余发票"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="统一社会信用代码" prop="code">
                <el-input v-model="queryParams.code" placeholder="请输入统一社会信用代码"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="总数量" prop="counts">
                <el-input v-model="queryParams.counts" placeholder="请输入总数量"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="过磅吨位" prop="dunwei">
                <el-input v-model="queryParams.dunwei" placeholder="请输入过磅吨位"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="供应商id" prop="supplierId">
                <el-input v-model="queryParams.supplierId" placeholder="请输入供应商id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="供应商名称" prop="supplierName">
                <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="审核状态" prop="state">
                <el-input v-model="queryParams.state" placeholder="请输入审核状态"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="开户行行号" prop="hanghao">
                <el-input v-model="queryParams.hanghao" placeholder="请输入开户行行号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="银行账号" prop="zhanghao">
                <el-input v-model="queryParams.zhanghao" placeholder="请输入银行账号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="开户行" prop="kaihuhang">
                <el-input v-model="queryParams.kaihuhang" placeholder="请输入开户行"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="开票金额" prop="kaipiao">
                <el-input v-model="queryParams.kaipiao" placeholder="请输入开票金额"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="上传人" prop="ddSongpeople">
                <el-input v-model="queryParams.ddSongpeople" placeholder="请输入上传人"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="发票日期" prop="fpDate">
                            <el-date-picker clearable v-model="queryParams.fpDate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择发票日期">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="发票编号" prop="nos">
                <el-input v-model="queryParams.nos" placeholder="请输入发票编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="到货id" prop="daohuoid">
                <el-input v-model="queryParams.daohuoid" placeholder="请输入到货id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="到货编号" prop="daohuono">
                <el-input v-model="queryParams.daohuono" placeholder="请输入到货编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="采购id" prop="caigouid">
                <el-input v-model="queryParams.caigouid" placeholder="请输入采购id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="采购编号" prop="caigouno">
                <el-input v-model="queryParams.caigouno" placeholder="请输入采购编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
                        <el-form-item label="到货日期" prop="daohuodate">
                            <el-date-picker clearable v-model="queryParams.daohuodate"
                                            type="date" value-format="yyyy-MM-dd" placeholder="请选择到货日期">
                            </el-date-picker>
                        </el-form-item>
            <el-form-item label="请购id" prop="qinggouid">
                <el-input v-model="queryParams.qinggouid" placeholder="请输入请购id"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="请购编号" prop="qinggouno">
                <el-input v-model="queryParams.qinggouno" placeholder="请输入请购编号"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="付款单" prop="fukuandan">
                <el-input v-model="queryParams.fukuandan" placeholder="请输入付款单"
                        clearable @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                        v-hasPermi="['develop:LvFapiao:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                        @click="handleUpdate" v-hasPermi="['develop:LvFapiao:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-popconfirm title="确认删除选择的数据项？" @confirm="handleDelete({})">
                    <el-button slot="reference" type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                               v-hasPermi="['develop:LvFapiao:remove']">删除</el-button>
                </el-popconfirm>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini"
                        @click="handleExport" v-hasPermi="['develop:LvFapiao:export']">导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table" :max-height="tableMaxHeight">
            <el-table-column type="selection" width="55" align="center"/>
                    <el-table-column label="${comment}" align="center" prop="id"/>
            <el-table-column label="备注" align="center" prop="remark"/>
            <el-table-column label="业务类型" align="center" prop="ywType"/>
            <el-table-column label="税率" align="center" prop="tax"/>
            <el-table-column label="发票金额" align="center" prop="money"/>
            <el-table-column label="剩余发票" align="center" prop="shengyu"/>
            <el-table-column label="统一社会信用代码" align="center" prop="code"/>
            <el-table-column label="总数量" align="center" prop="counts"/>
            <el-table-column label="过磅吨位" align="center" prop="dunwei"/>
            <el-table-column label="供应商id" align="center" prop="supplierId"/>
            <el-table-column label="供应商名称" align="center" prop="supplierName"/>
            <el-table-column label="审核状态" align="center" prop="state"/>
            <el-table-column label="开户行行号" align="center" prop="hanghao"/>
            <el-table-column label="银行账号" align="center" prop="zhanghao"/>
            <el-table-column label="开户行" align="center" prop="kaihuhang"/>
            <el-table-column label="开票金额" align="center" prop="kaipiao"/>
            <el-table-column label="开票文件" align="center" prop="kpfile"/>
            <el-table-column label="过磅单文件" align="center" prop="guobangdan"/>
            <el-table-column label="直发货回执单" align="center" prop="zhifahuo"/>
            <el-table-column label="上传人" align="center" prop="ddSongpeople"/>
                    <el-table-column label="发票日期" align="center" prop="fpDate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.fpDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="发票编号" align="center" prop="nos"/>
            <el-table-column label="到货id" align="center" prop="daohuoid"/>
            <el-table-column label="到货编号" align="center" prop="daohuono"/>
            <el-table-column label="采购id" align="center" prop="caigouid"/>
            <el-table-column label="采购编号" align="center" prop="caigouno"/>
                    <el-table-column label="到货日期" align="center" prop="daohuodate" width="180">
                        <template slot-scope="scope">
                            <span>{{ parseTime(scope.row.daohuodate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                        </template>
                    </el-table-column>
            <el-table-column label="请购id" align="center" prop="qinggouid"/>
            <el-table-column label="请购编号" align="center" prop="qinggouno"/>
            <el-table-column label="付款单" align="center" prop="fukuandan"/>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit"
                            @click="handleUpdate(scope.row)" v-hasPermi="['develop:LvFapiao:edit']">修改</el-button>
                    <el-popconfirm :title="`确认删除当前数据项？`" @confirm="handleDelete(scope.row)"
                                   style="margin-left: 10px;">
                        <el-button slot="reference" size="mini" type="text" icon="el-icon-delete"
                                   v-hasPermi="['develop:LvFapiao:remove']">删除</el-button>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

        <lvFapiao-form ref="form" @ok="getList"></lvFapiao-form>
    </div>
</template>

<script>
    import { deleteAction, getAction } from '@/api/manage'
    import LvFapiaoForm from '@/views/develop/lvFapiao/module/LvFapiaoForm'

    export default {
        name: "LvFapiaoList",
        components: {
            LvFapiaoForm,
        },
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 到货发票表格数据
                dataList: [],
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    ywType: null,
                    tax: null,
                    money: null,
                    shengyu: null,
                    code: null,
                    counts: null,
                    dunwei: null,
                    supplierId: null,
                    supplierName: null,
                    state: null,
                    hanghao: null,
                    zhanghao: null,
                    kaihuhang: null,
                    kaipiao: null,
                    kpfile: null,
                    guobangdan: null,
                    zhifahuo: null,
                    ddSongpeople: null,
                    fpDate: null,
                    nos: null,
                    daohuoid: null,
                    daohuono: null,
                    caigouid: null,
                    caigouno: null,
                    daohuodate: null,
                    qinggouid: null,
                    qinggouno: null,
                    fukuandan: null
                },
                url: {
                    list:'/lvFapiao/lvFapiao/list',
                    remove:'/lvFapiao/lvFapiao/',
                    export:'/lvFapiao/lvFapiao/export',
                },
                tableMaxHeight: window.innerHeight - 320,
            };
        },
        created() {
            this.getList();
            window.addEventListener('resize', this.getTableHeight);
        },
        destroyed () {
            window.removeEventListener('resize', this.getTableHeight)
        },
        methods: {
            /** 查询到货发票列表 */
            getList() {
                this.loading = true;
                getAction(this.url.list, this.queryParams).then(response => {
                    this.dataList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            getTableHeight () {
                this.tableHeight = window.innerHeight - 320
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length !== 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.$refs.form.handleAdd();
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.$refs.form.handleUpdate(row);
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                deleteAction(this.url.remove, ids).then(response => {
                    this.getList();
                    this.$modal.msgSuccess("删除成功");
                }).catch(() => {});
            },
            /** 导出按钮操作 */
            handleExport() {
                this.download(this.url.export, {
                    ...this.queryParams
                }, `lvFapiao_${new Date().getTime()}.xlsx`)
            },
        }
};
</script>
